package com.zhong.dagger2.app;

import android.app.Application;
import android.content.Context;

import com.apkfuns.logutils.LogUtils;
import com.zhong.dagger2.di.component.AppComponent;
import com.zhong.dagger2.di.component.DaggerAppComponent;
import com.zhong.dagger2.di.module.ApiModule;
import com.zhong.dagger2.di.module.AppModule;

/*
 * 项目名:    Dagger2Test
 * 包名       com.zhong.dagger2.app
 * 文件名:    App
 * 创建者:    ZJB
 * 创建时间:  2017/10/14 on 18:10
 * 描述:     TODO
 */
public class App extends Application {


    private static App instance;
    private static AppComponent appComponent;


    public static Context getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        initLog();
    }

    /**
     * 初始化Log
     */
    private void initLog() {
        LogUtils.getLogConfig()
                .configAllowLog(true)
                .configTagPrefix("TAG")
                .configShowBorders(true)
                .configFormatTag("%d{HH:mm:ss:SSS} %t %c{-5}");
    }

    /**
     * 初始化全局Component
     * @return
     */
    public static AppComponent getAppComponent() {
        if (appComponent == null) {
            appComponent = DaggerAppComponent.builder()
                    .apiModule(new ApiModule())
                    .appModule(new AppModule(instance))
                    .build();
        }
        return appComponent;
    }

}
